package com.esri.core.portal;

import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.tasks.ags.PortalFetchThumbnail;
import com.esri.core.internal.tasks.ags.ab;
import com.esri.core.internal.tasks.ags.ac;
import com.esri.core.internal.tasks.ags.ad;
import com.esri.core.internal.tasks.ags.ae;
import com.esri.core.internal.tasks.ags.al;
import com.esri.core.internal.util.d;
import com.tencent.smtt.sdk.TbsVideoCacheTask;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import org.achartengine.internal.a;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class PortalItem {
    Portal a;
    String b;
    String c;
    long d;
    long e;
    String f;
    String g;
    PortalItemType h;
    String i;
    List<String> j;
    String k;
    String l;
    Envelope m;
    SpatialReference n;
    String o;
    String p;
    int q;
    int r;
    float s;
    int t;
    PortalAccess u;
    String v;
    List<String> w;

    /* JADX INFO: Access modifiers changed from: package-private */
    public PortalItem(Portal portal) {
        this.a = portal;
    }

    public static PortalItem fetchItem(Portal portal, String str) throws Exception {
        return new ab(new al(portal), portal.findSharingUrl(), str, portal.b).execute();
    }

    public InputStream fetchData() throws Exception {
        return new ad(new al(this.a), this.a.findSharingUrl(), this.b, this.a.b).execute();
    }

    public List<PortalItemComment> fetchComments() throws Exception {
        String str = this.b;
        if (str == null || "".equals(str)) {
            return null;
        }
        return new ac(new al(this.a), this.a.findSharingUrl(), this.b, this.a.b).execute();
    }

    List<PortalItem> a(PortalRelationshipType portalRelationshipType, PortalRelationshipDirection portalRelationshipDirection) throws Exception {
        String str = this.b;
        if (str == null || "".equals(str)) {
            return null;
        }
        al alVar = new al(this.a);
        alVar.a(portalRelationshipType);
        if (portalRelationshipDirection != null) {
            alVar.a(portalRelationshipDirection);
        }
        return new ae(alVar, this.a.findSharingUrl(), this.b, this.a.b).execute();
    }

    public byte[] fetchThumbnail() throws Exception {
        String str = this.l;
        if (str == null || str.trim().length() == 0 || "null".equalsIgnoreCase(this.l)) {
            return null;
        }
        return new PortalFetchThumbnail(b(), this.a.b).execute();
    }

    private final String b() {
        try {
            return this.a.findSharingUrl() + "/content/items/" + this.b + "/info/" + this.l;
        } catch (Exception unused) {
            return null;
        }
    }

    public static PortalItem fromJson(JsonParser jsonParser, Portal portal) throws Exception {
        if (d.c(jsonParser)) {
            PortalItem portalItem = new PortalItem(portal);
            jsonParser.enable(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS);
            jsonParser.enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS);
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if (currentName.equals("accessInformation")) {
                    portalItem.o = jsonParser.getText();
                } else if (currentName.equals("avgRating")) {
                    portalItem.s = jsonParser.getFloatValue();
                } else if (currentName.equals("description")) {
                    portalItem.i = jsonParser.getText();
                } else if (currentName.equals("extent")) {
                    if (jsonParser.getText().equals("null")) {
                        portalItem.m = null;
                    } else {
                        jsonParser.nextToken();
                        try {
                            if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                                jsonParser.nextToken();
                                double doubleValue = jsonParser.getDoubleValue();
                                jsonParser.nextToken();
                                double doubleValue2 = jsonParser.getDoubleValue();
                                jsonParser.nextToken();
                                jsonParser.nextToken();
                                jsonParser.nextToken();
                                double doubleValue3 = jsonParser.getDoubleValue();
                                jsonParser.nextToken();
                                double doubleValue4 = jsonParser.getDoubleValue();
                                jsonParser.nextToken();
                                jsonParser.nextToken();
                                portalItem.m = new Envelope(doubleValue, doubleValue2, doubleValue3, doubleValue4);
                            }
                        } catch (JsonParseException unused) {
                            PrintStream printStream = System.err;
                            printStream.println("Error occurred while parsing the extent field of this Item : " + portalItem.b);
                        }
                    }
                } else if (currentName.equals("id")) {
                    portalItem.b = jsonParser.getText();
                } else if (currentName.equals("modified")) {
                    portalItem.e = jsonParser.getLongValue();
                } else if (currentName.equals("name")) {
                    portalItem.f = jsonParser.getText();
                } else if (currentName.equals("numComments")) {
                    portalItem.q = jsonParser.getIntValue();
                } else if (currentName.equals("numRatings")) {
                    portalItem.r = jsonParser.getIntValue();
                } else if (currentName.equals("numViews")) {
                    portalItem.t = jsonParser.getIntValue();
                } else if (currentName.equals("owner")) {
                    portalItem.c = jsonParser.getText();
                } else if (currentName.equals("snippet")) {
                    portalItem.k = jsonParser.getText();
                } else if (currentName.equals("spatialReference")) {
                    String text = jsonParser.getText();
                    if (text == null || "null".equals(text)) {
                        portalItem.n = null;
                    } else {
                        try {
                            try {
                                portalItem.n = SpatialReference.create(Integer.parseInt(text));
                            } catch (NumberFormatException unused2) {
                                portalItem.n = SpatialReference.create(jsonParser.getText());
                            }
                        } catch (Exception unused3) {
                            PrintStream printStream2 = System.err;
                            printStream2.println("Unable to construct spatial reference from " + jsonParser.getText());
                        }
                    }
                } else if (currentName.equals("tags")) {
                    portalItem.j = new ArrayList();
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        portalItem.j.add(jsonParser.getText());
                    }
                } else if (currentName.equals("thumbnail")) {
                    portalItem.l = jsonParser.getText();
                } else if (currentName.equals(a.b)) {
                    portalItem.g = jsonParser.getText();
                } else if (currentName.equals("type")) {
                    portalItem.h = PortalItemType.a(jsonParser.getText());
                } else if (currentName.equals("created")) {
                    portalItem.d = jsonParser.getLongValue();
                } else if (currentName.equals("uploaded")) {
                    portalItem.d = jsonParser.getLongValue();
                } else if (currentName.equals("access")) {
                    portalItem.u = PortalAccess.a(jsonParser.getText(), portal.isPreVersion162());
                } else if (currentName.equals(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL)) {
                    portalItem.v = jsonParser.getText();
                } else if (currentName.equals("licenseInfo")) {
                    portalItem.p = jsonParser.getText();
                } else if (currentName.equals("typeKeywords")) {
                    portalItem.w = new ArrayList();
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        portalItem.w.add(jsonParser.getText());
                    }
                } else {
                    jsonParser.skipChildren();
                }
            }
            return portalItem;
        }
        return null;
    }

    public Portal getPortal() {
        return this.a;
    }

    public String getItemId() {
        return this.b;
    }

    public String getOwner() {
        return this.c;
    }

    public long getCreated() {
        return this.d;
    }

    public long getModified() {
        return this.e;
    }

    public String getName() {
        return this.f;
    }

    public String getTitle() {
        return this.g;
    }

    public PortalItemType getType() {
        return this.h;
    }

    public String getDescription() {
        return this.i;
    }

    public List<String> getTags() {
        return this.j;
    }

    public String getSnippet() {
        return this.k;
    }

    public String getThumbnailFileName() {
        return this.l;
    }

    public Envelope getExtent() {
        return this.m;
    }

    public SpatialReference getSpatialReference() {
        return this.n;
    }

    public String getCredits() {
        return this.o;
    }

    public String getLicenseInfo() {
        return this.p;
    }

    public int getNumComments() {
        return this.q;
    }

    public int getNumRatings() {
        return this.r;
    }

    public float getAvgRating() {
        return this.s;
    }

    public int getNumViews() {
        return this.t;
    }

    public PortalAccess getAccess() {
        return this.u;
    }

    public List<String> getTypeKeywords() {
        return this.w;
    }

    String a() {
        return this.v;
    }

    public int hashCode() {
        PortalAccess portalAccess = this.u;
        int hashCode = ((portalAccess == null ? 0 : portalAccess.hashCode()) + 31) * 31;
        String str = this.o;
        int hashCode2 = (((hashCode + (str == null ? 0 : str.hashCode())) * 31) + Float.floatToIntBits(this.s)) * 31;
        String str2 = this.i;
        int hashCode3 = (hashCode2 + (str2 == null ? 0 : str2.hashCode())) * 31;
        String str3 = this.b;
        int hashCode4 = (hashCode3 + (str3 == null ? 0 : str3.hashCode())) * 31;
        String str4 = this.p;
        int hashCode5 = str4 == null ? 0 : str4.hashCode();
        long j = this.e;
        int i = (((hashCode4 + hashCode5) * 31) + ((int) (j ^ (j >>> 32)))) * 31;
        String str5 = this.f;
        int hashCode6 = (((((((i + (str5 == null ? 0 : str5.hashCode())) * 31) + this.q) * 31) + this.r) * 31) + this.t) * 31;
        String str6 = this.c;
        int hashCode7 = (hashCode6 + (str6 == null ? 0 : str6.hashCode())) * 31;
        String str7 = this.k;
        int hashCode8 = (hashCode7 + (str7 == null ? 0 : str7.hashCode())) * 31;
        List<String> list = this.j;
        int hashCode9 = (hashCode8 + (list == null ? 0 : list.hashCode())) * 31;
        String str8 = this.l;
        int hashCode10 = (hashCode9 + (str8 == null ? 0 : str8.hashCode())) * 31;
        String str9 = this.g;
        int hashCode11 = (hashCode10 + (str9 == null ? 0 : str9.hashCode())) * 31;
        PortalItemType portalItemType = this.h;
        int hashCode12 = portalItemType != null ? portalItemType.hashCode() : 0;
        long j2 = this.d;
        return ((hashCode11 + hashCode12) * 31) + ((int) (j2 ^ (j2 >>> 32)));
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj != null && (obj instanceof PortalItem)) {
            PortalItem portalItem = (PortalItem) obj;
            if (this.u != portalItem.u) {
                return false;
            }
            String str = this.o;
            if (str == null) {
                if (portalItem.o != null) {
                    return false;
                }
            } else if (!str.equals(portalItem.o)) {
                return false;
            }
            if (Float.floatToIntBits(this.s) != Float.floatToIntBits(portalItem.s)) {
                return false;
            }
            String str2 = this.i;
            if (str2 == null) {
                if (portalItem.i != null) {
                    return false;
                }
            } else if (!str2.equals(portalItem.i)) {
                return false;
            }
            String str3 = this.b;
            if (str3 == null) {
                if (portalItem.b != null) {
                    return false;
                }
            } else if (!str3.equals(portalItem.b)) {
                return false;
            }
            String str4 = this.p;
            if (str4 == null) {
                if (portalItem.p != null) {
                    return false;
                }
            } else if (!str4.equals(portalItem.p)) {
                return false;
            }
            if (this.e != portalItem.e) {
                return false;
            }
            String str5 = this.f;
            if (str5 == null) {
                if (portalItem.f != null) {
                    return false;
                }
            } else if (!str5.equals(portalItem.f)) {
                return false;
            }
            if (this.q == portalItem.q && this.r == portalItem.r && this.t == portalItem.t) {
                String str6 = this.c;
                if (str6 == null) {
                    if (portalItem.c != null) {
                        return false;
                    }
                } else if (!str6.equals(portalItem.c)) {
                    return false;
                }
                String str7 = this.k;
                if (str7 == null) {
                    if (portalItem.k != null) {
                        return false;
                    }
                } else if (!str7.equals(portalItem.k)) {
                    return false;
                }
                List<String> list = this.j;
                if (list == null) {
                    if (portalItem.j != null) {
                        return false;
                    }
                } else if (!list.equals(portalItem.j)) {
                    return false;
                }
                String str8 = this.l;
                if (str8 == null) {
                    if (portalItem.l != null) {
                        return false;
                    }
                } else if (!str8.equals(portalItem.l)) {
                    return false;
                }
                String str9 = this.g;
                if (str9 == null) {
                    if (portalItem.g != null) {
                        return false;
                    }
                } else if (!str9.equals(portalItem.g)) {
                    return false;
                }
                return this.h == portalItem.h && this.d == portalItem.d;
            }
            return false;
        }
        return false;
    }

    public String toString() {
        return "PortalItem [itemId=" + this.b + ", owner=" + this.c + ", created=" + this.d + ", modified=" + this.e + ", name=" + this.f + ", title=" + this.g + ", type=" + this.h + ", description=" + this.i + ", tags=" + this.j + ", snippet=" + this.k + ", thumbnail=" + this.l + ", extent=" + this.m + ", spatialReference=" + this.n + ", credits=" + this.o + ", licenseInfo=" + this.p + ", numComments=" + this.q + ", numRatings=" + this.r + ", avgRating=" + this.s + ", numViews=" + this.t + ", access=" + this.u + "]";
    }

    public void clear() {
        this.u = null;
        this.o = null;
        this.i = null;
        this.m = null;
        this.b = null;
        this.p = null;
        this.f = null;
        this.c = null;
        this.a = null;
        this.k = null;
        this.n = null;
        this.j = null;
        this.g = null;
        this.h = null;
    }
}
